package coroutines.launch.mode

import kotlinx.coroutines.*

class LaunchAtomic {
    companion object {
        suspend fun launchAtomic(scope: CoroutineScope): Job {
            return scope.launch(context = Dispatchers.IO, start = CoroutineStart.ATOMIC) {
                println("launch atmoic start : ${Thread.currentThread().name}")
                Thread.sleep(1000)
                println("launch atmoic start delay(1000): ${Thread.currentThread().name}")
                delay(1000)
                println("launch atmoic delay(1000) end : ${Thread.currentThread().name}")
                println("launch atmoic end : ${Thread.currentThread().name}")
            }
        }
    }
}

fun main() {
    runBlocking {
        val job = LaunchAtomic.launchAtomic(this)

//        job.cancel()
//        job.start()
    }
}